<template>

	<view class="wrap" v-if="list.length!=1">

		<!--  -->
		<view class="content">
			<picker @change="bindPickerChange($event,list)" :value="index" :range-key="'name'" range-key="name"
				:range="list">
				<view class="dis" style="justify-content: space-between;">
					<view class="tit">
						可用优惠券{{list.length}}
					</view>

					<view class="uni-input">{{list[index].name}}></view>
				</view>

			</picker>
		</view>
	</view>

</template>

<script>
	import {
		getCouponsOrder
	} from '@/api/togeterRich/index.js'
	export default {
		props: ["preOrderNo"],
		watch: {
			// 监听值的变化
			preOrderNo(newVal, oldVal) {
				this.init(newVal)
				console.log(newVal, oldVal, 'newVal, oldVal')
				// 在这里执行相应的操作
			}
		},
		data() {
			return {
				list: [],
				array: [],
				index: 0,
			}

		},
		mounted() {
			this.init()
		},
		methods: {
			bindPickerChange(e, arr) {

				this.index = e.detail.value
				this.$emit("getCountId", this.list[this.index].id)

			},
			init(preOrderNo) {
				// console.log("请求优惠券接口uhnklm;")
				let data = {
					cid: 0,
					couponId: 4,
					createTime: "2023-11-16 09:48:38",
					id: 0,

					minPrice: "0.00",
					money: "100.00",
					name: "暂不使用优惠券",
					primaryKey: "4",
					status: 0,
					type: "receive",
					uid: 4,
					updateTime: "2023-12-11 15:55:46",
					useEndTimeStr: "2024-02-24",
					useStartTimeStr: "2023-11-16",
					useTime: null,
					useType: 1,
				}
				getCouponsOrder(preOrderNo).then(res => {
					// console.log(res, 'shuju')
					this.list = res.data
					this.list.unshift(data)
					// console.log(this.list, '应该是不适应吧')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {

		margin-bottom: 20rpx;
		background: #fff;
		width: 100%;
		padding: 30rpx;

		.tit {
			font-size: 32rpx;
			color: #3D3D3D;
			align-items: center;
		}

		.content {
			margin: 20rpx 0;

		}
	}
</style>